﻿<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/CmsSystem/MasterPage/AdminForm.Master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>弹出设置</title>
    <link href="/App_Themes/default/CoreEdit.css" rel="stylesheet" type="text/css" />
    <script src="../../../Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="/Scripts/core.js" type="text/javascript"></script>
    <script src="/Scripts/jqGrid/lan/grid.locale-cn.js" type="text/javascript"></script>
    <link href="/App_Themes/Default/ui.jqgrid.css" rel="stylesheet" type="text/css" />
    <link href="/App_Themes/Default/jqueryui/jquery-ui-1.7.1.custom.css" rel="stylesheet"
        type="text/css" />
    <script src="/Scripts/jqGrid/jquery.jqGrid.min.js" type="text/javascript"></script>
    <script src="/Scripts/json.js" type="text/javascript"></script>
    <script src="/Scripts/customgrideditor.js" type="text/javascript"></script>
    <script src="/Scripts/form.js" type="text/javascript"></script>
    <script type="text/javascript">
        FormID = "Sys_Popwin";
        var setting = {
            width:550,
            colNames: ['ID', '弹出编号', '标题', '字段名', '长度', '类型', '是否可见'],
            colModel: [
                     { name: 'Id', index: 'Id', width: 80, key: true, hidden: true },
                     { name: 'Popwinid', index: 'Popwinid', width: 120, hidden: true, editable: true, editoptions: { value: ID} },
                     { name: 'Title', index: 'Title', width: 150, editable: true },
                     { name: 'Fieldname', index: 'Fieldname', width: 80, editable: true },
                     { name: 'Length', index: 'Length', width: 80, editable: true },
                     { name: 'Type', index: 'Type', width: 80, editable: true, editoptions: { value: "1"} },
                      { name: 'Visibled', index: 'Visibled', width: 80, editable: true, edittype: "checkbox", formatter: "checkbox" }

                    ]
        };
        FormLoadCallBack = function (jsondata) {
            if (jsondata["Detail"] && jsondata["Detail"].length > 0) {
                for (var i in jsondata["Detail"]) {
                    var row = jsondata["Detail"][i];
                    if (typeof (row) == "function")
                        continue;
                    if (row["Type"] == "1")
                        $("#DETAIL_1").addRowData(row["Id"], row);
                    else if (row["Type"] == "2")
                        $("#DETAIL_2").addRowData(row["Id"], row);
                }
            }
            return true;
        }
        $(function () {
            var assign = {};
            assign["Popwinid"] = ID;
            gridLoad("DETAIL_1", setting, assign);
            setting.colModel[5]["editoptions"] = { value: "2" };
            gridLoad("DETAIL_2", setting, assign);

            $("[name=LISTSQL],[name=TREESQL]").blur(function () {
                var sql = $(this).text();
                var name = $(this).attr("name");
                getColumns(sql, function (data) {
                    var opts = [];
                    opts.push("<option value=''>请选择</option>");
                    for (var i in data) {
                        opts.push("<option>" + data[i] + "</option>");
                    }
                    if (name == "LISTSQL") {
                        $("[name=LISTKEYFIELD]").empty().append(opts.join(""));
                    }
                    else if (name == "TREESQL") {
                        $("[name=TREEKEYFIELD],[name=TREEPARENTFIELD]").empty().append(opts.join(""));
                    }
                });
            });
            $("#btnBuildList,#btnBuildTree").click(function () {
                var id = $(this).attr("id");
                var sql = "";
                var gridid = "";
                if (id == "btnBuildList") {
                    sql = $("[name=LISTSQL]").text();
                    gridid = "DETAIL_1";
                }
                else {
                    sql = $("[name=TREESQL]").text();
                    gridid = "DETAIL_2";
                }
                getColumns(sql, function (data) {
                    for (var i in data) {
                        if (typeof (data[i]) == "function")
                            continue;
                        var row = {};
                        row["Fieldname"] = data[i];
                        row["Popwinid"] = ID;
                        AddGridRow(gridid, row);
                    }
                });

            });
        });
        function getColumns(sql, callback) {
            $.getJSON("/tools/json.ashx?param=db&type=info&act=getcolumns&sql=" + escape(sql), function (data) {
                callback(data);
            });
        }        
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script type="text/javascript">
        function Save(callback) {
            var option = [];
            if ($("[name=ID]").size() < 1) {
                option = [{ name: "ID", value: ID}];
            }
            var lastSel = getjqGridLastSel("DETAIL_1");
            jQuery('#DETAIL_1').jqGrid('saveRow', lastSel, false, "clientArray");
            var listjson = jQuery("#DETAIL_1").getRowData();
            lastSel = getjqGridLastSel("DETAIL_2");
            jQuery('#DETAIL_2').jqGrid('saveRow', lastSel, false, "clientArray");
            var listjson2 = jQuery("#DETAIL_2").getRowData();
            listjson = jQuery.merge(listjson, listjson2);
            option.push({ name: "Detail", value: JSON.stringify(listjson) });
            formSubmit(FormID, option, function () {
                if (callback && typeof (callback) == "function")
                    callback();
                FormSubmitCallback()
            });
        }
    </script>
    <div>
        <input type="button" id="btnBuildList" value="重新生成列表列" />
        <input type="button" id="btnBuildTree" value="重新生成树列" />
    </div>
    <fieldset>
        <legend>基本设置</legend>
        <div class="row">
            <label class="label">
                标题</label>
            <label class="input">
                <input type="text" name="TITLE" class="I" /></label>
            <label class="label">
                编号</label>
            <label class="input">
                <input type="text" name="ALIAS" class="I" /></label>
        </div>
        <div class="row">
            <label class="label">
                弹出类型</label>
            <label class="input">
                <select name="TYPE" class="I">
                    <option value="1">只有列表</option>
                    <option value="2">只有树</option>
                    <option value="12">左右结构</option>
                </select>
            </label>
            <label class="label">
                列表主键</label>
            <label class="input">
                <select name="LISTKEYFIELD" class="I">
                </select>
            </label>
        </div>
        <div class="srow">
            <label class="label">
                列表SQL</label>
            <label class="input">
                <textarea name="LISTSQL" rows="20" class="I"></textarea>
            </label>
            <label class="label">
                树SQL</label>
            <label class="input">
                <textarea name="TREESQL" rows="20" class="I"></textarea>
            </label>
        </div>
        <div class="row">
            <label class="label">
                树主键</label>
            <label class="input">
                <select name="TREEKEYFIELD" class="I">
                </select>
            </label>
            <label class="label">
                树父键</label>
            <label class="input">
                <select name="TREEPARENTFIELD" class="I">
                </select>
            </label>
        </div>
    </fieldset>
    <div>
        <fieldset style="float: left;">
            <legend>列表设置</legend>
            <div id="gridpagerDETAIL_1">
            </div>
            <table id="DETAIL_1">
            </table>
        </fieldset>
        <fieldset style="float: left;">
            <legend>树设置</legend>
            <div id="gridpagerDETAIL_2">
            </div>
            <table id="DETAIL_2">
            </table>
        </fieldset>
        <b style="clear: both;"></b>
    </div>
</asp:Content>
